﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Engine.Classes {
    import flash.display.*;
    import flash.geom.*;
    import Engine.Helpers.*;
    import Engine.*;

	/**
	 * 一个简单的支持放大和缩小的Tile
	 */
    public class SimpleTile extends Tile {

        protected var m_transformMat:Matrix;
        protected var m_rawBitmapData:BitmapData;
        protected var m_transformedBitmapData:BitmapData;
        protected var m_zoomLevel:Number;

        public function SimpleTile(_arg1:BitmapData=null){
            this.m_rawBitmapData = _arg1;
            if (this.m_rawBitmapData){ 
                this.generateTransformMatrix();
            };
        }
        override public function getType():String{
            return (Constants.ASSET_TILE);
        }
        public function setBitmapData(_arg1:BitmapData):void{
            if (this.m_rawBitmapData){
                this.m_rawBitmapData.dispose();
            };
            this.m_rawBitmapData = _arg1;
            this.generateTransformMatrix();
        }
        public function getRawBitmapData():BitmapData{
            return (this.m_rawBitmapData);
        }
        override public function getBitmapData():BitmapData{
            this.generateTransformedBitmap();
            return (this.m_transformedBitmapData);
        }
        protected function generateTransformedBitmap():void{
            var _local2:Matrix;
            var _local1:Number = (GlobalEngine.viewport.getZoom() * Constants.TILE_SCALE);
            if (this.m_zoomLevel != _local1){
                _local2 = this.m_transformMat.clone();
                _local2.scale(_local1, _local1);
                this.m_transformedBitmapData = new BitmapData((tileWidth * _local1), (tileHeight * _local1), true, 0);
                this.m_transformedBitmapData.draw(this.m_rawBitmapData, _local2, null, null, null, true);
                this.m_zoomLevel = _local1;
            };
        }
        protected function generateTransformMatrix():void{
            var _local1:IntVector2;
            var _local2:Point;
            if (this.m_rawBitmapData != null){
                _local1 = new IntVector2(tileWidth, tileHeight);
                _local2 = new Point((_local1.x / this.m_rawBitmapData.width), (_local1.y / this.m_rawBitmapData.height));
                this.m_transformMat = new Matrix();
                this.m_transformMat.scale(_local2.x, _local2.y);
            };
        }

    }
}//package Engine.Classes 
